/*!
 * atuacao.js
 * @project MB Consultoria Jurídica
 * @developer Thiago Braga <thibraga06@gmail.com>
 * @url www.mbconsultoriajuridica.com.br
 */


/**
 * @function loadNews
 * @description Read RSS content via ajax and write on page.
 * @uses jGFeed Plugin
 */
var loadNews = (function () {
  var html = '',
    feeds = feeds || {},
    news = $('#news'),
    loading = news.parent().find('.icon-spinner');

  $.jGFeed('http://www.oab.org.br/rss', function (feeds) {
    if (!feeds)
      return false;

    html += '<div class="row-fluid">';
    for (var i = 0; i < 3; i++) {
      entry = feeds.entries[i];
      switch (i) {
        case 0: html += '<li class="span7"><div class="thumbnail"><div class="caption"><h4><a href="'+ entry.link +'">'+ entry.title +'</a></h4><p>'+ entry.content.substring(0, 1300) +'...</p><span class="label label-inverse">Leia mais</span><a href="'+ entry.link +'">'+ entry.link.substring(11) +'</a></div></div></li>'; break;
        default: html += '<li class="span5"><div class="thumbnail"><div class="caption"><h5><a href="'+ entry.link +'">'+ entry.title +'</a></h5><p>'+ entry.content.substring(0, 250) +'...</p><span class="label label-inverse">Leia mais</span><a href="'+ entry.link +'">'+ entry.link.substring(11) +'</a></div></div></li>';
      }
    }
    html += '</div>';

    for (var i = 3, j = 0; i < feeds.entries.length - 1; i++, j++) {
      var entry = feeds.entries[i];
      if (j == 0 || j % 3 == 0)
        html += '<div class="row-fluid">';

      html += '<li class="span4"><div class="thumbnail"><div class="caption"><h5><a href="'+ entry.link +'">'+ entry.title +'</a></h5><p>'+ entry.content.substring(0, 350) +'...</p><span class="label label-inverse">Leia mais</span><a href="'+ entry.link +'">'+ entry.link.substring(11) +'</a></div></div></li>';
      if (j > 0 && (j + 1) % 3 == 0)
        html += '</div>';
    }

    news.append(html);
    loading.hide();
  }, 10);
})();